const http = require('node:http');

const server = http.createServer((req, res) => {
    let data = '';
    req.on('data', (chunk) => {
        data += chunk;
    });

    req.on('end', () => {
        let method = req.method;
        let url = req.url;
        let headers = JSON.stringify(req.headers);
        let httpVersion = req.httpVersion;
        res.writeHead(200, {
            'content-type': 'text/html'
        });

        let content = `<p>data: ${data}</p>` +
            `<p>method: ${method}</p>` +
            `<p>url: ${url}</p>` +
            `<p>headers: ${headers}</p>` +
            `<p>httpVersion: ${httpVersion}</p>`;
        res.end(content);
    });
});

let port = 3001;
server.listen(port, () => {
    console.log(`listen port ${port}`);
})